package daoTest;

import com.ldzy.Utils.MyBatisUtils;
import com.ldzy.pojo.User;
import com.ldzy.dao.UserDao;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class daoUser {
    SqlSession sqlSession=null;
    @Before
    public  void  init(){
        sqlSession= MyBatisUtils.getSqlssion();
    }
    @After
    public  void  destory(){
        sqlSession.commit();
        sqlSession.close();
    }
//    @Test
//    public  void allTest(){
//        UserDao userDao=sqlSession.getMapper(UserDao.class);
//        List<User> list=userDao.all();
//        for (int i=0;i<list.size();i++)
//            System.out.println(list.get(i).getUname());
//    }
//    @Test
    public  void  findById(){

       User user= sqlSession.selectOne("com.ldzy.dao.UserDao.findById",1);
        System.out.println(user.toString());

    }
    @Test
    public  void findByID3(){
        User user=sqlSession.selectOne("com.ldzy.dao.UserDao.findByid3",1);
        System.out.println(user.toString());
    }
    @Test
    public  void  findById4(){
        User user=sqlSession.selectOne("com.ldzy.dao.UserDao.findById4",1);
        System.out.println(user.toString());
    }
    @Test
    public  void  getUsersfinById(){
        UserDao userDao=sqlSession.getMapper(UserDao.class);
        User user=userDao.findById(1);
        System.out.println(user);
    }
    @Test
    public  void  getUsersfinAll(){
        UserDao userDao=sqlSession.getMapper(UserDao.class);
        List<User> userList=userDao.all();
        for (int i=0;i<userList.size();i++)
            System.out.println(userList.get(i).toString());

    }
    @Test
    public  void  getUsersfinAdd(){
        UserDao userDao=sqlSession.getMapper(UserDao.class);
        User user=new User();
        user.setUname("Tom");
        user.setUage(11);
        userDao.addname(user);
        List<User> userList=userDao.all();
        for (int i=0;i<userList.size();i++)
            System.out.println(userList.get(i).toString());

    }
    @Test
    public  void editTest(){
        UserDao userDao=sqlSession.getMapper(UserDao.class);
        User user=new User();
        user.setUid(4);
        user.setUname("Rname");
        userDao.ewd(user);
    }
    @Test
    public  void ediIdUsersTest(){
        UserDao userDao=sqlSession.getMapper(UserDao.class);
        userDao.updateDUser(4,"tomu1");

  }
  @Test
    public  void getTest(){
        UserDao userDao=sqlSession.getMapper(UserDao.class);
        User user=userDao.findById(1);
        System.out.println(user.toString());
    }
    @Test
    public  void getTeat1(){
        UserDao userDao=sqlSession.getMapper(UserDao.class);
        User user=userDao.findByIdWinidCard(1);
        System.out.println(user.toString());
    }
}
